package com.wb.core11IO.字符流;

import java.io.*;

/**
 * @author 黄衡熙
 * @version 1.0
 */
public class Test02_缓冲流 {
    public static void main(String[] args) {
        try (
                BufferedReader br = new BufferedReader(new FileReader("hello.txt"));
                BufferedWriter bw = new BufferedWriter(new FileWriter("aa.txt"));
                PrintWriter out = new PrintWriter("aaa.txt");
        ) {
            // 按行读,当没有数据时返回null
//            System.out.println(br.readLine());
            String data = null;
            while ((data = br.readLine()) != null) {
//                System.out.println(data);
                // 将数据写入到文件中
                // 此时写入的数据并没有包含换行符
                bw.write(data);
                // 需要手动写入换行符
                bw.write("\n");
                // 可以通过PrintWriter打印
                // print():没有换行
                // println():自带换行
                out.println(data);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
